body {
    background: var(--primary-bg-gradient);
    color: var(--primary-text);
}

:root {
    --pest-card-height: 280px; /* Default value, will be overridden by JS */
}

main {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-height));
    box-sizing: border-box;
    padding: 0 20px;
}

/* 查询条件区域样式 */
.search-container {
    background: rgba(36, 50, 81, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--card-border-radius, 12px);
    padding: 20px;
    margin-bottom: 20px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.search-form {
    width: 100%;
}

.search-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
}

.search-item {
    display: flex;
    flex-direction: column;
    min-width: 150px;
}

.search-item label {
    color: var(--primary-text);
    font-size: 14px;
    margin-bottom: 5px;
    font-weight: 500;
}

.search-input,
.search-select {
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--primary-text);
    font-size: 14px;
    transition: all 0.3s ease;
}

.search-input:focus,
.search-select:focus {
    outline: none;
    border-color: var(--primary-color, #4CAF50);
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

.search-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.search-select option {
    background: var(--card-bg, #2a3a5c);
    color: var(--primary-text);
}

.search-btn,
.reset-btn {
    padding: 8px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-right: 10px;
}

/* 这将使查询按钮样式与重置按钮一致 */
.search-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--primary-text);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.search-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-1px);
}

.reset-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--primary-text);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.reset-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-1px);
}

/* 将按钮容器设置为水平排列 */
.search-buttons {
    flex-direction: row;
    align-items: flex-end; /* 与其他控件底部对齐 */
}

/* 响应式设计 */
@media (max-width: 768px) {
    .search-row {
        flex-direction: column;
        align-items: stretch;
    }
    
    .search-item {
        min-width: auto;
        width: 100%;
    }
    
    .search-item:last-child {
        flex-direction: row;
        gap: 10px;
        margin-top: 10px;
    }
    
    .search-btn,
    .reset-btn {
        flex: 1;
        margin-right: 0;
    }
}

.pest-history-container {
    display: flex;
    flex-direction: column;
    height: calc(100% - 120px); /* 减去查询条件区域的高度 */
    width: 100%;
    justify-content: space-between;
    color: var(--primary-text);
    flex: 1; /* 确保容器可以扩展填充可用空间 */
}

.pest-detection-container {
    display: flex;
    gap: 20px;
    height: 100%;
}

.image-container {
    flex: 3;
    position: relative;
    border-radius: var(--card-border-radius);
    overflow: hidden;
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
    display: flex;
    justify-content: center;
    align-items: center;
}

#pest-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#bbox-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.results-container {
    flex: 1;
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--card-border-radius);
    padding: 20px;
    overflow-y: auto;
    color: var(--primary-text);
}

.results-container h2 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 18px;
    font-weight: 600;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 10px;
    color: var(--primary-text);
}

.results-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
}

.result-item {
    display: flex;
    align-items: center;
    padding: 12px 10px;
    border-bottom: 1px solid var(--divider-color);
    color: var(--primary-text);
}

.result-item:last-child {
    border-bottom: none;
}

.pest-color-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 12px;
    flex-shrink: 0;
}

.pest-name {
    flex-grow: 1;
    font-size: 15px;
    color: var(--primary-text);
}

.pest-count {
    font-size: 15px;
    color: var(--secondary-text);
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    overflow-y: auto; /* 允许垂直滚动以查看所有卡片 */
    min-height: 450px; /* 确保至少有足够的高度显示多行卡片 */
    flex: 1; /* 让网格容器自动扩展填充可用空间 */
    padding-bottom: 16px; /* 添加底部内边距，避免卡片紧贴底部 */
}

.history-card {
    background: rgba(36, 50, 81, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--card-border-radius, 12px);
    padding: 10px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
    height: var(--pest-card-height);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
    justify-content: flex-start; /* 从顶部开始排列内容 */
    color: var(--primary-text) !important;
}

.history-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.card-image-container {
    width: 100%;
    height: 110px; /* 减小图片容器高度，从120px减少到110px */
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 5px; /* 减少底部边距，从10px减少到5px */
    flex-shrink: 0;
    display: flex;
    align-items: center; /* Vertical centering for image */
    position: relative;
    cursor: zoom-in;
    -webkit-tap-highlight-color: transparent; /* 移除触摸高亮 */
}

.card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-image-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.1);
    opacity: 0;
    transition: opacity 0.3s;
}

.card-image-container:hover::after {
    opacity: 1;
}

.card-content {
    flex-grow: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* 从顶部开始排列 */
    align-items: center; /* 居中对齐 */
    color: var(--primary-text);
    padding: 10px 0 3px 0; /* 增加顶部内边距 */
    text-align: center; /* 文本居中 */
}

.card-content .timestamp {
    font-size: 12px; /* 减小字体大小 */
    color: var(--secondary-text, #a9b9d1);
    margin-bottom: 8px; /* 增加底部边距 */
    text-align: center; /* 居中显示 */
    width: 100%; /* 确保占满整行 */
}

.card-content .summary-title {
    font-size: 14px; /* 减小字体大小 */
    font-weight: 600;
    margin-bottom: 5px; /* 减少底部边距 */
    color: var(--primary-text);
    text-align: left; /* 左对齐显示 */
    width: 100%; /* 确保占满整行 */
}

.results-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 4px; /* 减少间距 */
    overflow-y: visible; /* 确保内容可见 */
    max-height: none; /* 移除最大高度限制 */
    margin-top: 0; /* 移除顶部边距 */
    justify-content: center; /* 水平居中 */
    align-items: center; /* 垂直居中 */
    width: 100%; /* 确保占满整行 */
}

/* 添加滚动条样式，确保在内容过多时可以滚动查看 */
.results-summary::-webkit-scrollbar {
    width: 4px;
}

.results-summary::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

.results-summary::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

.pest-result-item {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 3px 8px; /* 增加内边距 */
    border-radius: 4px; /* 增加圆角 */
    font-size: 12px; /* 增加字体大小 */
    white-space: nowrap;
    color: var(--primary-text);
    margin: 2px; /* 增加边距 */
    line-height: 1.4; /* 增加行高 */
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 60px; /* 增加最小宽度 */
}

/* 未识别到虫害的特殊样式 */
.pest-result-item.no-detection {
    background-color: rgba(76, 175, 80, 0.3);
    color: rgba(255, 255, 255, 0.95);
    font-weight: 500;
    padding: 3px 8px; /* 减少内边距 */
    min-width: 90px; /* 减少宽度 */
}

.pagination-container {
    padding: 15px 0;
    margin-top: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    min-height: 50px; /* Ensure pagination has minimum height */
    color: var(--primary-text);
}

/* 确保分页控件的文字颜色 */
.pagination-container span,
.pagination-container a {
    color: var(--primary-text);
}

/* 图片模态框样式 */
.image-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.image-modal.active {
    display: flex;
}

.modal-image-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 15px;
    color: white;
    font-size: 32px;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.5);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1001;
    -webkit-tap-highlight-color: transparent; /* 移除触摸高亮 */
    touch-action: manipulation; /* 优化触摸行为 */
}

.modal-caption {
    color: white;
    margin-top: 20px;
    font-size: 16px;
    text-align: center;
}

/* 加载状态、错误信息和空数据提示样式 */
.loading-indicator, .error-message, .empty-data-message {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
    width: 100%;
    color: var(--primary-text);
    font-size: 16px;
    text-align: center;
}

.loading-indicator {
    position: relative;
    padding-top: 40px;
}

.loading-indicator:before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    margin-left: -15px;
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--primary-text);
    animation: spin 1s linear infinite;
}

.error-message {
    color: #ff6b6b;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .history-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 12px;
    }
    
    .history-card {
        padding: 10px;
    }
    
    .card-image-container {
        height: 120px;
        margin-bottom: 10px;
    }
    
    .card-content .timestamp {
        font-size: 12px;
    }
    
    .card-content .summary-title {
        font-size: 14px;
    }
    
    .pest-result-item {
        padding: 3px 6px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .history-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 10px;
    }
    
    .card-image-container {
        height: 100px;
    }
}

/* 修改日期时间输入框的图标颜色为白色 */
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
.search-input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    filter: invert(1); /* 将图标颜色反转为白色 */
    opacity: 0.8; /* 稍微降低不透明度，使其看起来更柔和 */
    cursor: pointer; /* 添加指针样式，提高可用性 */
}

/* 确保在不同浏览器中都有效 */
input[type="datetime-local"]::-webkit-inner-spin-button,
input[type="datetime-local"]::-webkit-clear-button,
.search-input[type="datetime-local"]::-webkit-inner-spin-button,
.search-input[type="datetime-local"]::-webkit-clear-button {
    filter: invert(1);
    opacity: 0.8;
}